package com.easemob.a;

import android.util.Log;
import android.view.SurfaceView;
import com.easemob.media.AVNative;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;

public class a
{
  private int a = 640;
  private int b = 480;
  private int c = 600;
  private EGLContext d;
  private EGLSurface e;
  private EGLDisplay f;
  private EGLConfig g;
  private int h;
  private SurfaceView i;
  private AVNative j = new AVNative();
  private static a k = null;

  public static a a()
  {
    if (k == null)
      k = new a();
    return k;
  }

  public void a(SurfaceView paramSurfaceView)
  {
    this.i = paramSurfaceView;
  }

  public void a(int paramInt1, int paramInt2, byte[] paramArrayOfByte)
  {
    this.j.nativeProcessYUV(paramInt1, paramInt2, paramArrayOfByte);
  }

  public void a(int paramInt1, int paramInt2, int paramInt3)
  {
    this.j.onNativeResize(paramInt1, paramInt2, a(paramInt3));
  }

  public void b()
  {
    this.j.nativeResume();
  }

  int a(int paramInt)
  {
    int m = -2062217214;
    switch (paramInt)
    {
    case 8:
      Log.v("SDL", "pixel format A_8");
      break;
    case 10:
      Log.v("SDL", "pixel format LA_88");
      break;
    case 9:
      Log.v("SDL", "pixel format L_8");
      break;
    case 7:
      Log.v("SDL", "pixel format RGBA_4444");
      m = -2059268094;
      break;
    case 6:
      Log.v("SDL", "pixel format RGBA_5551");
      m = -2059137022;
      break;
    case 1:
      Log.v("SDL", "pixel format RGBA_8888");
      m = -2042224636;
      break;
    case 2:
      Log.v("SDL", "pixel format RGBX_8888");
      m = -2044321788;
      break;
    case 11:
      Log.v("SDL", "pixel format RGB_332");
      m = -2079258623;
      break;
    case 4:
      Log.v("SDL", "pixel format RGB_565");
      m = -2062217214;
      break;
    case 3:
      Log.v("SDL", "pixel format RGB_888");
      m = -2045372412;
      break;
    case 5:
    default:
      Log.v("SDL", "pixel format unknown " + paramInt);
    }
    return m;
  }

  public static boolean a(int paramInt1, int paramInt2)
  {
    Log.d("SDL", "to call initEGL");
    a().d();
    return a().c(paramInt1, paramInt2);
  }

  public static void c()
  {
    a().k();
  }

  public static void a(String paramString)
  {
  }

  private boolean c(int paramInt1, int paramInt2)
  {
    if (this.f == null)
    {
      Log.v("SDL", "initEGL" + paramInt1 + "." + paramInt2);
      try
      {
        EGL10 localEGL10 = (EGL10)EGLContext.getEGL();
        localEGLDisplay = localEGL10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        int[] arrayOfInt1 = new int[2];
        localEGL10.eglInitialize(localEGLDisplay, arrayOfInt1);
        n = 1;
        int i1 = 4;
        int i2 = 0;
        if (paramInt1 == 2)
          i2 = i1;
        else if (paramInt1 == 1)
          i2 = n;
        int[] arrayOfInt2 = { 12352, i2, 12344 };
        EGLConfig[] arrayOfEGLConfig = new EGLConfig[1];
        int[] arrayOfInt3 = new int[1];
        if ((!localEGL10.eglChooseConfig(localEGLDisplay, arrayOfInt2, arrayOfEGLConfig, 1, arrayOfInt3)) || (arrayOfInt3[0] == 0))
        {
          Log.e("SDL", "No EGL config available");
          return false;
        }
        EGLConfig localEGLConfig = arrayOfEGLConfig[0];
        this.f = localEGLDisplay;
        this.g = localEGLConfig;
        this.h = paramInt1;
        i();
      }
      catch (Exception localException)
      {
        EGLDisplay localEGLDisplay;
        int n;
        Log.v("SDL", localException);
        for (localEGLDisplay : localException.getStackTrace())
          Log.v("SDL", localEGLDisplay.toString());
      }
    }
    else
    {
      i();
    }
    return true;
  }

  private boolean i()
  {
    if ((this.f != null) && (this.g != null))
    {
      EGL10 localEGL10 = (EGL10)EGLContext.getEGL();
      if (this.d == null)
        j();
      Log.v("SDL", "Creating new EGL Surface");
      EGLSurface localEGLSurface = localEGL10.eglCreateWindowSurface(this.f, this.g, this.i, null);
      if (localEGLSurface == EGL10.EGL_NO_SURFACE)
      {
        Log.e("SDL", "Couldn't create surface");
        return false;
      }
      if (!localEGL10.eglMakeCurrent(this.f, localEGLSurface, localEGLSurface, this.d))
      {
        Log.e("SDL", "Old EGL Context doesnt work, trying with a new one");
        j();
        if (!localEGL10.eglMakeCurrent(this.f, localEGLSurface, localEGLSurface, this.d))
        {
          Log.e("SDL", "Failed making EGL Context current");
          return false;
        }
      }
      this.e = localEGLSurface;
      return true;
    }
    return false;
  }

  private boolean j()
  {
    EGL10 localEGL10 = (EGL10)EGLContext.getEGL();
    int m = 12440;
    int[] arrayOfInt = { m, this.h, 12344 };
    this.d = localEGL10.eglCreateContext(this.f, this.g, EGL10.EGL_NO_CONTEXT, arrayOfInt);
    if (this.d == EGL10.EGL_NO_CONTEXT)
    {
      Log.e("SDL", "Couldn't create context");
      return false;
    }
    return true;
  }

  private void k()
  {
    try
    {
      EGL10 localEGL10 = (EGL10)EGLContext.getEGL();
      localEGL10.eglWaitNative(12379, null);
      localEGL10.eglWaitGL();
      localEGL10.eglSwapBuffers(this.f, this.e);
    }
    catch (Exception localException)
    {
      Log.v("SDL", "flipEGL(): " + localException);
      for (StackTraceElement localStackTraceElement : localException.getStackTrace())
        Log.v("SDL", localStackTraceElement.toString());
    }
  }

  public void d()
  {
    try
    {
      EGL10 localEGL10 = (EGL10)EGLContext.getEGL();
      if (this.e != null)
      {
        localEGL10.eglMakeCurrent(this.f, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        localEGL10.eglDestroySurface(this.f, this.e);
        this.e = null;
      }
      if (this.d != null)
      {
        localEGL10.eglDestroyContext(this.f, this.d);
        this.d = null;
      }
      if (this.f != null)
      {
        localEGL10.eglTerminate(this.f);
        this.f = null;
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public SurfaceView e()
  {
    return this.i;
  }

  public void b(SurfaceView paramSurfaceView)
  {
    this.i = paramSurfaceView;
  }

  public void b(int paramInt1, int paramInt2)
  {
    this.a = paramInt1;
    this.b = paramInt2;
  }

  public int f()
  {
    return this.a;
  }

  public int g()
  {
    return this.b;
  }

  public int h()
  {
    return this.c;
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.a.a
 * JD-Core Version:    0.6.1
 */